#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef intmax_t ML;
const int MAXN=1E5+7;
const LL MOD = 1e9+7;
LL Fac[MAXN], RFac[MAXN];
LL Dao(LL ask) {
    LL k = MOD - 2;
    LL ret = 1;
    while (k) {
        if (k&1) {
            ret = (ret * ask) % MOD;
        }
        k = (k>>1);
        ask = (ask*ask) % MOD;
    }
    return ret;
}
void Init() {
    Fac[0]=1; RFac[0]=1;
    for (int i=1; i<MAXN; ++i) {
        Fac[i] = (Fac[i-1] * i) % MOD;
    }
    RFac[MAXN-1] = Dao(Fac[MAXN-1]);
    for (int i=MAXN-2; i; --i) {
        RFac[i] = RFac[i+1] * (i+1) % MOD;
    }
}
LL C(LL n, LL k) {
    return Fac[n] * RFac[k] % MOD * RFac[n-k] % MOD;
}
struct node {
    int n, m;
    int i;//询问位置
    node(int a, int b) {n=a; m=b;}
    node() {}
};
node ask[MAXN];
bool cmp1(node a, node b) {
    int x1=a.n/100, x2=b.n/100;
    int y1=a.m/100, y2=b.m/100;
    if (x1 != x2) return x1<x2;
    if (y1 != y2) return y1<y2;
    if (a.n != b.n) return a.n<b.n;
    return a.m<b.m;
}
LL arr[MAXN];

int main() {
#ifdef hai
    freopen("in.txt", "r", stdin);
#endif
    Init();
    int T;
    cin>>T;
    int n,m;
    for (int i=1; i<=T; ++i) {
        scanf("%d %d", &n, &m);
        ask[i].n = n;
        ask[i].m = m;
        ask[i].i = i;
    }
    ask[0].n = 0;
    ask[0].m = 0;
    ask[0].i = 0;
    sort(ask+1, ask+1+T, cmp1);
    arr[0]=1;
    LL dao2 = Dao(2);
    for (int i=1; i<=T; ++i) {
        int pn=ask[i-1].n, pm=ask[i-1].m;
        n=ask[i].n; m=ask[i].m;
        LL res = arr[ask[i-1].i];
        if (pn<n) {
            for (int j=pn; j<n; ++j) {
                res = (2*res - C(j, pm) + MOD) % MOD;
            }
        }
        else {
            for (int j=pn; j>n; --j) {
                res = (res + C(j-1, pm)) * dao2 % MOD;
            }
        }
        if (m>pm) {
            for (int j=pm; j<m; ++j) {
                res = (res + C(n, j+1)) % MOD;
            }
        }
        else {
            for (int j=pm; j>m; --j) {
                res = (res - C(n, j) + MOD) % MOD;
            }
        }
        arr[ask[i].i] = res;
    }
    for (int i=1; i<=T; ++i) {
        printf("%lld\n", arr[i]);
    }
    return 0;
}
